#ifndef TITLEBAR_H
#define TITLEBAR_H

#include <QWidget>
#include "define.h"

namespace Ui {
class TitleBar;
}

class TitleBar : public QWidget
{
    Q_OBJECT

public:
    explicit TitleBar(const QString filePath, const QString content,
                      ButtonStyle style, QColor color, QWidget *parent);
    ~TitleBar();

    // 初始化标题栏的图标, 标题, 和按钮
    void init(const QString filePath, const QString content, ButtonStyle style);
    void initStyleSheet(const QString path = ":/action/images");
    void setTitleIcon(const QString filePath);
    void setTitleContent(const QString content, QColor color = Qt::white);
    void setButtonStyle(ButtonStyle style);

    // 实现鼠标拖动
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;

    void paintEvent(QPaintEvent *event) override;

private:
    Ui::TitleBar *ui;

    QColor color;
    ButtonStyle style;
    bool moveable;
    QPoint titleBarStartPos;

signals:
    void closeButtonClicked();
    void minButtonClicked();
    void maxButtonClicked();
    void restoreButtonClicked();

private slots:
    void on_pushButtonMax_clicked();
    void on_pushButtonRestore_clicked();
    void on_pushButtonMin_clicked();
    void on_pushButtonClose_clicked();
};

#endif // TITLEBAR_H
